﻿using System;
using System.Web.UI;



namespace mojoPortal.Web.RS.CRM
{
    public partial class RSMyAgents : RSBasePage
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                InitializeReadyServicePage("Agents");
                RSUserIdentity userIdentity = GetRSUserIdentity();
                if (Session["SELECTED_AGENTID_IS_MY_DOWNLINE_LEAD"] != null)
                {
                    int agentid = Convert.ToInt32(Session["SELECTED_AGENTID_IS_MY_DOWNLINE_LEAD"].ToString());
                    ucAgentHeaderControl.LoadAgentData(userIdentity.RSCompanyId, agentid);
                    if (userIdentity.RSFirstName != ucAgentHeaderControl.AgentFirstName && userIdentity.RSLastName != ucAgentHeaderControl.AgentLastName)
                    {
                        tpMyAgent.HeaderText = ucAgentHeaderControl.AgentFirstName + " - Agents";
                        tpMyClient.HeaderText = ucAgentHeaderControl.AgentFirstName + " - Clients";
                    }
                    else
                    {
                        tpMyAgent.HeaderText = "My Agents";
                        tpMyClient.HeaderText = "My Clients";
                        Session["SELECTED_AGENTID_IS_MY_DOWNLINE_LEAD"] = null;
                    }
                    ucMyAgentListControl.LoadMyAgentList(userIdentity.RSCompanyId, agentid);
                }
                else
                {
                    ucAgentHeaderControl.LoadAgentData(userIdentity.RSCompanyId, userIdentity.RSEmployeeId);
                    ucMyAgentListControl.LoadMyAgentList(userIdentity.RSCompanyId, userIdentity.RSEmployeeId);
                }
            }
        }

        private void ActiveTabChanged()
        {
            switch (tcMyHome.ActiveTabIndex)
            {
                case 0:
                    //Response.Redirect("RSMyAgents.aspx");
                    break;
                case 1:
                    Response.Redirect("RSMyClients.aspx");
                    break;
                //default:
            }
        }

        protected void tcMyHome_OnActiveTabChanged(object sender, EventArgs e)
        {
            ActiveTabChanged();
        }

    }

}
